package cn.enjoyedu.ch01.bio.me;

import cn.enjoyedu.ch01.Ch01Const;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class BioServer {


    private static ServerSocket server;

    private static ExecutorService executorService = Executors.newFixedThreadPool(5);

    public static void main(String[] args) throws IOException {


        try {
            server = new ServerSocket(Ch01Const.DEFAULT_PORT);
            System.out.println("服务器启动，端口号" + Ch01Const.DEFAULT_PORT);

            while (true) {
                Socket socket = server.accept();
                System.out.println("有新的客户端连接====");
                executorService.execute(new BioServerHandler(socket));
            }

        } finally {
            if (server == null) {
                server.close();
            }
        }

    }


}
